package com.qf.mp;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

//字段自动填充管理器
@Component
public class UserMetaHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Object status = getFieldValByName("status", metaObject);
        Object createTime = getFieldValByName("createTime", metaObject);
        if(null == status){
            //字段为空，可以进行填充
            setFieldValByName("status", 1, metaObject);
        }
        if(null == createTime){
            //字段为空，可以进行填充
            setFieldValByName("createTime", new Date(), metaObject);
        }


    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
